<template>

</template>

<script>
import store from '../store/index'
import * as auth from '../api/auth'
import * as user from '../api/user'
export default {
  name: 'auth',
  methods: {
    auth(){
      let that = this;
      if(that.$route.query.code){
        auth.getUser(that.$route.query.code)
          .then(res => {
            if(res.status !== 200){
              return
            }
            this.getInfo();
            res = res.data;
            if(res.token !== ''){
              store.commit('setToken', res.token);
            }
            if(res.needBind === true){
              that.$router.push({path: '/binding'})
            }else{
              that.$router.push({path: '/home'})
            }
          })
      }else{
        window.location.href = process.env.BASE_API + '/auth/code?redirect-url=http://www.niceleads.cn/auth';
      }
    },
    getInfo(){
      user.getUserInfo()
        .then(res => {
          store.commit('setUserInfo',rea.data);
        })
    }
  }
}
</script>

<style scoped>

</style>
